package rsawrapper
import (
	"crypto/aes"
	"errors"
	"crypto/cipher"
	"bytes"
)

// AES加密
func Encrypt(src, key, iv []byte) ([]byte, error) {
	// 验证输入参数
	// 必须为aes.Blocksize的倍数
	if len(src)%aes.BlockSize != 0 {
		return nil, errors.New("crypto/cipher: input not full blocks")
	}
	cblock, err := aes.NewCipher(key)
	if err != nil {
		panic("aes.NewCipher: " + err.Error())
	}

	mode := cipher.NewCBCEncrypter(cblock, iv)

	encryptText := make([]byte, len(src))
	mode.CryptBlocks(encryptText, src)

	return encryptText, nil
}
func PKCS5Padding(src []byte, blockSize int) []byte {
	padding := blockSize - len(src)%blockSize
	padtext := bytes.Repeat([]byte{byte(padding)}, padding)
	return append(src, padtext...)
}